package com.suxin.netty.heartbeat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * @Classname NioHandlerServer
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2021/1/6 21:09
 * @Created by ASUS
 */
public class NioHandlerServer extends ChannelInboundHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        // IdleStateEvent 空闲事件
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent stateEvent = (IdleStateEvent) evt;
            String eventType = "";
            switch (stateEvent.state()) {
                case READER_IDLE:
                    eventType = "读事件空闲";
                    break;
                case WRITER_IDLE:
                    eventType = "写事件空闲";
                    break;
                case ALL_IDLE:
                    eventType = "读写事件空闲";
                    break;
                default:
                    break;
            }
            System.out.println("客户端["+ctx.channel().remoteAddress()+"]的状态是：--->" + eventType);
        }
    }
}